//2009/08/24 00:16:35
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class ThrowTheBall
{
public:
    int timesThrown(int N, int M, int L)
    {
        vector<int> v(N, 0);
        int idx = 0;
		int ret = 0;
        while (v[idx] < M)
        {
            v[idx] ++;
			if(v[idx] == M) break;
			ret ++;
            if (v[idx] % 2 == 1) idx = (((idx - L) % N) + N ) % N;
			else idx = (((idx + L) % N) + N ) % N;
			cout << "idx: " << idx << endl;
        }
        return ret;
    }
};
